package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202410;

public class leetcode20241006 {
    public int canCompleteCircuit(int[] gas,int[] cost){
        /**
         * 加油站
         */
        int rest=0,run=0,start=0;
        for(int i=0;i<gas.length;i++){
            run+=(gas[i]-cost[i]);
            rest+=(gas[i]-cost[i]);
            if(run<0){
                start=i+1;
                run=0;
            }
        }
        return rest<0 ? -1 : start;
    }
}
